package cn.com.dhcc.app.pub.core.listener;

import javax.servlet.ServletContextEvent;

import cn.com.dhcc.app.core.base.CmCommon;
import cn.com.dhcc.app.core.base.InterceptorBean.SIGNAL;
import cn.com.dhcc.app.core.boot.BootParam;
import cn.com.dhcc.app.core.exception.InitException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.listener.AppInitListener;
import cn.com.dhcc.app.pub.core.AppPara;
import cn.com.dhcc.app.pub.module.resmgr.service.ResourceService;

/**
 * spring 容器启动之前的一些操作
 */
public class ResourceInitListener implements AppInitListener {

	@Override
	public void init(ServletContextEvent contextEvent, BootParam bootParam) throws InitException {
		if(AppPara.UAMS.AUTH_RESOURCE_MANAGED){
			try {
				CmCommon.getBean(ResourceService.class).loadResourceToCache();
				contextEvent.getServletContext().log("将菜单资源加入缓冲成功...");
			} catch (ServiceException e) {
				contextEvent.getServletContext().log("将菜单资源加入缓冲失败...", e);
			}
		}
	}
	@Override
	public void destroyed(ServletContextEvent contextEvent, BootParam bootParam) throws InitException {
	}
	@Override
	public SIGNAL onError(ServletContextEvent contextEvent, BootParam bootParam)
			throws InitException {
		return SIGNAL.STOP;
	}
}
